package com.lottemall.order.config;

import com.lottemall.order.interceptors.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 加入自己定义的组件
 */
@Configuration
@EnableConfigurationProperties(JwtProperties.class)
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private JwtProperties jwtProperties;
    /**
     * 实现方法：添加一个拦截器
     *
     * @param registry 注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加一个拦截器，拦截所有请求(后来改成拦截order的开头的，因为微信要调用我们的接口，通知我们用户是否支付成功)
        registry.addInterceptor(new UserInterceptor(jwtProperties)).addPathPatterns("/order/**");
    }
}
